#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1


# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

#DEB_MAKE_INSTALL_TARGET := install debroot=$(CURDIR)/debian/tmp prefix=$(CURDIR)/debian/tmp/usr

# Get supported python version and destdir
PYVERS  = $(shell pyversions -rv)

clean:
	dh_testdir
	dh_testroot
	rm -f *-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f config.sub config.guess
	dh_clean

config-common: python/engine/PinYin/py.db
	dh_testdir
	# Add here commands to configure the package.
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif
config-ext-%: config-common configure
	dh_testdir
	env PYTHON=python$* ./configure \
		--disable-static \
		--enable-english-writer=force --enable-pinyin \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr \
		CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"
	#mv -f config.status $@	
	touch $@

build: build-stamp
build-stamp: $(PYVERS:%=build-ext-%)
build-ext-%: config-ext-%
	dh_testdir
	# Add here commands to compile the package.
	$(MAKE)
	touch $@

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	# Add here commands to install the package into debian/python-scim.
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp NO_INDEX=true install
	dh_install --sourcedir=debian/tmp --fail-missing

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i ChangeLog
	dh_installdocs -i
	dh_pycentral -i
#	dh_python
#	dh_installman
	dh_link -i
	dh_compress -i -X.py
	dh_fixperms -i
	dh_installdeb -i
	dh_shlibdeps -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs -a ChangeLog
	dh_installdocs -a
	dh_pycentral
#	dh_pycentral -pscim-python-chinese
#	dh_pycentral -pscim-python-english
#	dh_python
#	dh_installman
	dh_link -a
	dh_strip -ppython-scim
	dh_compress -a -X.py
	dh_fixperms -a
#	dh_makeshlibs
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
